package com.structurizr.util;

import com.structurizr.Workspace;
import com.structurizr.view.ThemeUtils;
import org.junit.jupiter.api.Test;

import java.io.File;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class ThemeUtilsTests {

    @Test
    void inlineTheme() throws Exception {
        File themeFile = new File("src/test/resources/theme.json");

        try {
            Workspace theme = new Workspace("Theme", "");
            theme.getViews().getConfiguration().getStyles().addElementStyle("Tag").background("#ff0000").icon("logo.png");
            theme.getViews().getConfiguration().getStyles().addRelationshipStyle("Tag").color("#00ff00");
            ThemeUtils.toJson(theme, themeFile);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        Workspace workspace = new Workspace("Name", "Description");
        ThemeUtils.inlineTheme(workspace, themeFile);

        assertEquals(0, workspace.getViews().getConfiguration().getThemes().length);
        assertEquals("#ff0000", workspace.getViews().getConfiguration().getStyles().getElementStyle("Tag").getBackground());
        assertEquals("", workspace.getViews().getConfiguration().getStyles().getElementStyle("Tag").getIcon());
        assertEquals("#00ff00", workspace.getViews().getConfiguration().getStyles().getRelationshipStyle("Tag").getColor());
    }

}